class RegisterFile:
    def __init__(self):
        self.registers = [0] * 32  # 32个寄存器
        # 初始化几个常用寄存器
        self.registers[1] = 10  # $at
        self.registers[2] = 0x1000  # $v0 数据区域基址
        self.registers[3] = 15  # $v1

    def read(self, reg_num):
        """读取寄存器值"""
        if 0 <= reg_num < 32:
            return self.registers[reg_num]
        return 0

    def write(self, reg_num, value):
        """写入寄存器"""
        if 0 < reg_num < 32:  # $0不可写
            self.registers[reg_num] = value